﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CoreData;
using ActionServices;
using Helper;

namespace ZidoniCMS.Controllers
{
    public class AlbumController : BaseController
    {
        //
        // GET: /Album/
        public AlbumController(IAlbumActionService _album)
            : base(_album)
        { }
        /// <summary>
        /// List Album
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(int page=1, int PageSize=10)
        {
            var data = AlbumService.GetListByLINQ(x => x.Active == true).ToList();
            if (data != null && data.Count() > 0)
            {
                ViewBag.page = page;
                ViewBag.PageSize = PageSize;
                ViewBag.TotalPage = (int)Math.Ceiling((float)data.Count / (float)PageSize);
                data = data.Skip(PageSize * (page - 1)).Take(PageSize).ToList();
            }
            if (SessionManagement.GetSessionReturnToString("LANGUAGE") == ValueDefine.Language.en.ToString()) {
                foreach (var item in data) {
                    item.Name = item.NameEN;
                }
            }
            return View(data);
        }
        /// <summary>
        /// Detail Images
        /// </summary>
        /// <param name="id">Image ID</param>
        /// <returns></returns>
        public ActionResult Detail(int id = 0) {
            var data = AlbumService.GetByID(id);
            if (SessionManagement.GetSessionReturnToString("LANGUAGE") == ValueDefine.Language.en.ToString())
            {
                data.Name = data.NameEN;
            }
            return View(data);
        }
        /// <summary>
        /// Danh sách các hình ảnh ở footer
        /// </summary>
        /// <returns></returns>
        public ActionResult _ListAlbumFooter()
        {
            var data = AlbumService.GetList();
            if (SessionManagement.GetSessionReturnToString("LANGUAGE") == ValueDefine.Language.en.ToString())
            {
                foreach (var item in data)
                {
                    item.Name = item.NameEN;
                }
            }
            return PartialView(data);
        }
        /// <summary>
        /// Danh sách album bên phải trang chi tiết album
        /// </summary>
        /// <param name="id">ID của ảnh hiện tại</param>
        /// <returns></returns>
        public ActionResult _ListSmallAlbumRelation(int id) {
            var exits = AlbumService.GetByID(id);
            var data = new List<Album>();
            if (exits != null)
            {
                data = AlbumService.GetListByLINQ(x => x.Active == true && x.ID != id).ToList();
            }
            else
            {
                data = AlbumService.GetListByLINQ(x => x.Active == true).ToList();
            }
            if (SessionManagement.GetSessionReturnToString("LANGUAGE") == ValueDefine.Language.en.ToString())
            {
                foreach (var item in data)
                {
                    item.Name = item.NameEN;
                }
            }
            return PartialView(data);
        }
    }
}
